//package com.swift.authority.common.aspect;
//
//import com.swift.authority.common.annotation.TokenAuthority;
//import com.swift.authority.common.constant.CommonConstant;
//import com.swift.authority.common.exception.BusinessException;
//import com.swift.authority.common.util.JwtUtil;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//import org.springframework.web.context.request.RequestAttributes;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
///**
// * @author Administrator
// * @description :
// * @date 2022/06/19 13:42
// * @since open jdk 1.8
// */
//@Component
//@Aspect
//public class AuthAspect {
//    private Logger logger = LoggerFactory.getLogger(AuthAspect.class);
//
//    /**
//     * 方法一 token校验
//     */
//    @Pointcut("@annotation(com.swift.authority.common.annotation.TokenAuthority)")
//    private void authPointcut(){}
//
//    /**
//     * 方法二 token校验
//     */
////    @Pointcut("execution(public * com.swift.authority.application.controller.*.*(..))")
////    public void tokenValid() {
////    }
//
//    @Around("authPointcut()")
//    public Object handleControllerMethod(ProceedingJoinPoint joinPoint) throws Throwable {
//        Long startTime = System.currentTimeMillis();
//        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = attributes.getRequest();
//
//        //获取token并验证token
//        String authorization = request.getHeader("token");
//        if(StringUtils.isEmpty(authorization)){
//            logger.info("token不存在或已失效 ...");
//            throw new Throwable("token不存在或已失效 ...",new Throwable());
//
//        }
//        boolean token = JwtUtil.verify(authorization);
//        if(token){
//            //请求过程
//            Object  obj = joinPoint.proceed();
//        }
//        //是否需要刷新token
//        String result = JwtUtil.refreshToken(authorization);
//        if(!result.equalsIgnoreCase(CommonConstant.UN_EXPIRED)){
//            request.setAttribute("Authorization",result);
//        }
//        return joinPoint.proceed();
//    }
//}
